﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpeakOut.Model
{
    [Serializable]
    public class Tag
    {
        public virtual Guid TagId { get; set; }

        public virtual string Name { get; set; }

        public virtual Post Post { get; set; }

        public Tag()
        {
            TagId = Guid.Empty;
        }

        public override string ToString()
        {
            return string.Format("{0} # PostId:{1}", Name, Post.PostId);
        }

        private bool Equals(Tag other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.TagId.Equals(TagId);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Tag)) return false;
            return Equals((Tag) obj);
        }

        public override int GetHashCode()
        {
            return TagId.GetHashCode();
        }
    }
}
